package com.freeter.modules.controller;


import com.freeter.modules.gjs.entity.*;
import com.freeter.modules.gjs.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/app/master")
public class MasterController {
    @Autowired private UserRolesService userRolesService;
    @Autowired private MstrDivisionService mstrDivisionService;
    @Autowired private MstrCat00Service mstrCat00Service;
    @Autowired private MstrCat01Service mstrCat01Service;
    @Autowired private MstrCat02Service mstrCat02Service;
    @Autowired private MstrUomService mstrUomService;
    @Autowired private MstrItemsService mstrItemsService;
    @Autowired private MstrSiteService mstrSiteService;

    // 角色管理
    //@PreAuthorize("isAuthenticated()")
    @GetMapping("/roles")
    public List<UserRoles> listRoles() { return userRolesService.getAllUserRoles(); }
    //@PreAuthorize("isAuthenticated()")
    @PostMapping("/roles")
    public UserRoles createRole(@RequestBody UserRoles role) { return userRolesService.createUserRoles(role); }
    //@PreAuthorize("isAuthenticated()")
    @PutMapping("/roles/{id}")
    public UserRoles updateRole(@PathVariable Long id, @RequestBody UserRoles role) { return userRolesService.updateUserRoles(id, role); }
    //@PreAuthorize("isAuthenticated()")
    @DeleteMapping("/roles/{id}")
    public ResponseEntity<?> deleteRole(@PathVariable Long id) { userRolesService.deleteUserRoles(id); return ResponseEntity.ok().build(); }

    // 部门管理
    //@PreAuthorize("isAuthenticated()")
    @GetMapping("/divisions")
    public List<MstrDivision> listDivisions() { return mstrDivisionService.getAllDivisions(); }
    //@PreAuthorize("isAuthenticated()")
    @PostMapping("/divisions")
    public MstrDivision createDivision(@RequestBody MstrDivision division) { return mstrDivisionService.createDivision(division); }
    //@PreAuthorize("isAuthenticated()")
    @PutMapping("/divisions/{id}")
    public MstrDivision updateDivision(@PathVariable Long id, @RequestBody MstrDivision division) { return mstrDivisionService.updateDivision(id, division); }
    //@PreAuthorize("isAuthenticated()")
    @DeleteMapping("/divisions/{id}")
    public ResponseEntity<?> deleteDivision(@PathVariable Long id) { mstrDivisionService.deleteDivision(id); return ResponseEntity.ok().build(); }

    // 分类管理
    //@PreAuthorize("isAuthenticated()")
    @GetMapping("/cat1")
    public List<MstrCat00> listCat1() { return mstrCat00Service.listAll(); }
    //@PreAuthorize("isAuthenticated()")
    @PostMapping("/cat00")
    public ResponseEntity<?> createCat00(@RequestBody MstrCat00 cat) { mstrCat00Service.create(cat); return ResponseEntity.ok().build(); }
    //@PreAuthorize("isAuthenticated()")
    @PutMapping("/cat00/{id}")
    public ResponseEntity<?> updateCat00(@PathVariable Long id, @RequestBody MstrCat00 cat) { cat.setId(id); mstrCat00Service.update(cat); return ResponseEntity.ok().build(); }
    //@PreAuthorize("isAuthenticated()")
    @DeleteMapping("/cat00/{id}")
    public ResponseEntity<?> deleteCat00(@PathVariable Long id) { mstrCat00Service.delete(id); return ResponseEntity.ok().build(); }

    //@PreAuthorize("isAuthenticated()")
    @GetMapping("/cat2")
    public List<MstrCat01> listCat2() { return mstrCat01Service.listAll(); }
    //@PreAuthorize("isAuthenticated()")
    @PostMapping("/cat01")
    public ResponseEntity<?> createCat01(@RequestBody MstrCat01 cat) { mstrCat01Service.create(cat); return ResponseEntity.ok().build(); }
    //@PreAuthorize("isAuthenticated()")
    @PutMapping("/cat01/{id}")
    public ResponseEntity<?> updateCat01(@PathVariable Long id, @RequestBody MstrCat01 cat) { cat.setId(id); mstrCat01Service.update(cat); return ResponseEntity.ok().build(); }
    //@PreAuthorize("isAuthenticated()")
    @DeleteMapping("/cat01/{id}")
    public ResponseEntity<?> deleteCat01(@PathVariable Long id) { mstrCat01Service.delete(id); return ResponseEntity.ok().build(); }

    //@PreAuthorize("isAuthenticated()")
    @GetMapping("/cat3")
    public List<MstrCat02> listCat3() { return mstrCat02Service.listAll(); }
    //@PreAuthorize("isAuthenticated()")
    @PostMapping("/cat02")
    public ResponseEntity<?> createCat02(@RequestBody MstrCat02 cat) { mstrCat02Service.create(cat); return ResponseEntity.ok().build(); }
    //@PreAuthorize("isAuthenticated()")
    @PutMapping("/cat02/{id}")
    public ResponseEntity<?> updateCat02(@PathVariable Long id, @RequestBody MstrCat02 cat) { cat.setId(id); mstrCat02Service.update(cat); return ResponseEntity.ok().build(); }
    //@PreAuthorize("isAuthenticated()")
    @DeleteMapping("/cat02/{id}")
    public ResponseEntity<?> deleteCat02(@PathVariable Long id) { mstrCat02Service.delete(id); return ResponseEntity.ok().build(); }

    // 单位管理
    //@PreAuthorize("isAuthenticated()")
    @GetMapping("/uoms")
    public List<MstrUom> listUoms() { return mstrUomService.getAllUoms(); }
    //@PreAuthorize("isAuthenticated()")
    @PostMapping("/uoms")
    public MstrUom createUom(@RequestBody MstrUom uom) { return mstrUomService.createUom(uom); }
    //@PreAuthorize("isAuthenticated()")
    @PutMapping("/uoms/{id}")
    public MstrUom updateUom(@PathVariable Long id, @RequestBody MstrUom uom) { return mstrUomService.updateUom(id, uom); }
    //@PreAuthorize("isAuthenticated()")
    @DeleteMapping("/uoms/{id}")
    public ResponseEntity<?> deleteUom(@PathVariable Long id) { mstrUomService.deleteUom(id); return ResponseEntity.ok().build(); }

    // 物品管理
    //@PreAuthorize("isAuthenticated()")
    @GetMapping("/items")
    public List<MstrItems> listItems() { return mstrItemsService.getAllItems(); }
    //@PreAuthorize("isAuthenticated()")
    @PostMapping("/items")
    public MstrItems createItem(@RequestBody MstrItems item) { return mstrItemsService.createItem(item); }
    //@PreAuthorize("isAuthenticated()")
    @PutMapping("/items/{id}")
    public MstrItems updateItem(@PathVariable Long id, @RequestBody MstrItems item) { return mstrItemsService.updateItem(id, item); }
    //@PreAuthorize("isAuthenticated()")
    @DeleteMapping("/items/{id}")
    public ResponseEntity<?> deleteItem(@PathVariable Long id) { mstrItemsService.deleteItem(id); return ResponseEntity.ok().build(); }

    // 站点管理
    //@PreAuthorize("isAuthenticated()")
    @GetMapping("/sites")
    public List<MstrSite> listSites() { return mstrSiteService.getAllSites(); }
    //@PreAuthorize("isAuthenticated()")
    @PostMapping("/sites")
    public MstrSite createSite(@RequestBody MstrSite site) { return mstrSiteService.createSite(site); }
    //@PreAuthorize("isAuthenticated()")
    @PutMapping("/sites/{id}")
    public MstrSite updateSite(@PathVariable Long id, @RequestBody MstrSite site) { return mstrSiteService.updateSite(id, site); }
    //@PreAuthorize("isAuthenticated()")
    @DeleteMapping("/sites/{id}")
    public ResponseEntity<?> deleteSite(@PathVariable Long id) { mstrSiteService.deleteSite(id); return ResponseEntity.ok().build(); }
}